home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / SoundMusicSystem.h < prev    next >
Text File  |  1994-09-06  |  14KB  |  317 lines

  1. /*****************************************************/
  2. /*
  3. **    SoundMusicSys.h
  4. **
  5. **        Structures for handling the sounds used by system
  6. **
  7. **          (c) 1989-1994 by Halestorm, Inc, All Rights Reserved
  8. **  
  9. **
  10. **    History    -
  11. **     7/20/89    Created
  12. **     7/24/89    Created Asyncronous Sample List Player.
  13. **     12/3/89    Modified all tools to work with the Sound Driver instead of the
  14. **            Sound Manager (He got fired.)
  15. **    12/21/89 Added PlayTheSample.
  16. **    2/1/90    Added Sound Manager (he got hired as a consultant) and use it
  17. **            when system 6.0 or greater is around. (Better sound.   !!?!??)
  18. **    4/10/90    Fixed pause/resume sound to allocate/deallocate sound channel.
  19. **    7/3/90    Added a REST mechanisim to the SampleList player
  20. **    7/28/90    Added IsSoundListFinished() to the SampleList player
  21. **    7/31/90    Added IsSoundFXFinished()
  22. **    8/13/90    Moved example and StandAlone code to a seperate project.
  23. **  12/12/90    Added GetSoundWaveform() & GetSoundLength() & GetSoundDefaultRate().
  24. **    1/9/91    Added sound done call back function.
  25. **    3/4/91    Completed work on Sound Driver's call back.
  26. **    4/10/91    Fixed a bug in CalcPlaybackLength that calculated the wrong length.
  27. **    4/10/91    Added purgability of the samples.
  28. **    4/23/91    Added better compatibility to Think C version 3.0
  29. **    4/30/91    Put in support for snd resource type 1 and type 2.
  30. **    5/18/91    Changed to zone calls instead of globals.
  31. **    5/20/91    Mucking around for bug that Mick is having.
  32. **    5/20/91    Added csnd compressed resource based upon the LZSS algo.
  33. **    5/25/91    Added a FinisSoundChannel/InitSoundChannel inside of EndSound() for Mick
  34. **    5/27/91    Fixed potential bug with BeginSoundList() in which the sound may be
  35. **            loaded during a VBL!
  36. **    5/28/91    Modified to new Think C MPW like header names.
  37. **    6/18/91    Added delay to the starting of a new sound with BeginSound (4 Ticks).
  38. **    7/24/91    Added delay to the starting of a new sound with PlayTheSample (4 Ticks).
  39. **    8/5/91    Removed duplicate code in BeginSound & PlayTheSample.
  40. **    8/5/91    Added 2 tick delay to soundLength. Used in IsSoundFXFinished.
  41. **    8/5/91    Added BeginSoundReverse & BeginSoundSection.
  42. **    8/6/91    Fixed some memory management problems with SoundMemorySize.
  43. **    8/6/91    Added a semaphore to the vbl task.
  44. **    9/9/91    Cleaned up for Think C 5.0
  45. **    9/9/91    Added PLAY_ALL_SAMPLE
  46. **    9/9/91    Changed all 'int's to 'short int'. Sorry guys. This is because I want
  47. **            16 bit integers.
  48. **    10/8/91    Added sound looping features. BeginSoundLoop(), BeginSoundEnvelope(),
  49. **            and BeginSoundEnvelopeProc().
  50. **    11/11/91 Added SoundLock().
  51. **    1/22/92    Put in buffer SndDoCommands for looped & enveloped sounds
  52. **    3/9/92    Modifed for MPW and removed all THINK C 3 & 4 compiler stuff
  53. **    3/23/92    Added access to"Private-Sound/Music.h"
  54. **    5/1/92    Added the SoundChannelRestart() function
  55. **    7/10/92    Combined SoundSys.h & MusicSys.h into new and improved version
  56. **    7/10/92    Added new calls to initilize & clean up the system
  57. **    7/10/92    Heavily modified for Rev 3 of the sound system.
  58. **    7/10/92    Now calling jim's sound mixer
  59. **    7/13/92    Added BeginMasterFadeOut & FadeLevel
  60. **    7/18/92    Fully intergrated the SoundManager out and replaced with "SoundGod"
  61. **    7/26/92    Added ChangeOuputQuality() and fixed bug with BeginSongLooped
  62. **    7/31/92    Fixed weird bug with MPW passing of 32-bit value "shorts"!!
  63. **    7/31/92    Fixed BeginMasterFadeOut code.
  64. **    8/4/92    Change playback rate command to 16.16 fixed value. Sorry guys.
  65. **    8/6/92    Built a mult-voice tracker, to work with sound effects.
  66. **    8/23/92    Added 2 pt intrepolation    
  67. **    8/24/92    Added ChangeSystemVoices
  68. **    12/4/92    Added LoadSound
  69. **    12/9/92    Added FreeSound
  70. **    12/29/92 ResumeSoundMusicSystem and PauseSoundMusicSystem now return
  71. **            errors
  72. **    3/6/93    Fixed the SoundDone callback system.
  73. **    3/6/93    Elimated the playback decay govenour.
  74. **    3/16/93    Added BeginMasterFadeIn
  75. **    3/19/93    Added SetSongDoneCallBack
  76. **    5/31/93    Made LoadSong/FreeSong work
  77. **    6/14/93    Changed VBL task to be out of the system heap
  78. **    6/24/93    Added StartFilePlayback, EndFilePlayback, and ChangeFilePlaybackRate
  79. **    6/24/93    Added IsThisSoundFXFinished
  80. **    7/2/93    Added EndSoundList
  81. **    7/13/93    Fixed File streaming stop bug
  82. **    7/14/93    Worked on stopping callback bug
  83. **    7/15/93    Think I fixed the callback bug
  84. **    7/21/93    Forced callbacks to use a long for MPW
  85. **    7/25/93    Fixed bug with resume while file playback is in progress
  86. **    7/26/93    Changed all callbacks to be pascal based
  87. **    9/2/93    Fixed macro bug with FreeSong
  88. **    9/15/93    Fixed a looping bug with BeginSongLoop
  89. **    9/19/93    Exposed DeltaDecompressHandle for Larry, for those who want to decompress a 'csnd' resource
  90. **    10/27/93 Fixed bug with ReleaseRegisteredSounds that caused a crash
  91. **    11/18/93 Added ServiceFilePlayback to the API for StartFilePlayback
  92. **    11/18/93 Added GetSoundLoopStart & GetSoundLoopEnd
  93. **    11/18/93 Added SetMasterVolume & GetMasterVolume
  94. **    12/4/93    Added code/data cache flush to callback
  95. **    12/4/93    Added GetCurrentMidiClock() & SetCurrentMidiClock()
  96. **    1/11/94    Cleaned header up a bit.
  97. **    2/28/94    Added PlayTheSampleWithID
  98. **    3/15/94    Found a nasty callback problem and fixed it.
  99. **    4/5/94    Fixed memory leak with instrument loading
  100. **    4/29/94    Removed external div and mul function references for A4 land.
  101. **    6/23/94    Updated to CodeWarrior
  102. **    9/2/94    Added mixedmode manager support
  103. **
  104. */
  105. /*****************************************************/
  106.  
  107.  
  108. #ifndef HALESTORM_DRIVER
  109. #define HALESTORM_DRIVER
  110.  
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114.  
  115. // SOUND DRIVER EQUATES
  116.  
  117. /* Definitions for Sound resources */
  118. #define SOUND_END                -1                    /* End Sound for list */
  119.  
  120. /* Defines for sound functions */
  121. #define SOUND_RATE_DEFAULT        0L                    /* Default rate */
  122. #define SOUND_RATE_FAST        0x56EE8BA3L            /* Fast */
  123. #define SOUND_RATE_MEDIUM        0x2B7745D1L            /* Medium */
  124. #define SOUND_RATE_MOSEY        SOUND_RATE_FAST/3    /* Mosey */
  125. #define SOUND_RATE_SLOW        SOUND_RATE_MEDIUM/2    /* Slow */
  126.  
  127. #define SOUND_RATE_22k        SOUND_RATE_FAST
  128. #define SOUND_RATE_11k        SOUND_RATE_MEDIUM
  129. #define SOUND_RATE_7k            SOUND_RATE_MOSEY
  130. #define SOUND_RATE_5k            SOUND_RATE_SLOW
  131.  
  132. #define REST_SAMPLE            -1L                /* When using the SampleList mechanisim, this will
  133.                                             ** rest (no sound) for the duration of the length
  134.                                             */
  135. #define PLAY_ALL_SAMPLE        -2L                /* When using the SampleList mechanisim, this will
  136.                                             ** play the entire sound if this is put into the SampleList
  137.                                             ** theLength parameter.
  138.                                             */
  139.  
  140. #define CUSTOM_PLAY_ID    ((short int)0x8000)        /* ID value of samples played with PlayTheSample */
  141. #define FILE_PLAY_1_ID        ((short int)0x8001)        /* ID value of samples played with StartFilePlayback (Buffer 1) */
  142. #define FILE_PLAY_2_ID        ((short int)0x8002)        /* ID value of samples played with StartFilePlayback (Buffer 1) */
  143.  
  144. /* Ranges for SetMasterFade() and FadeLevel() */
  145. #define MAX_VOLUME        0x100
  146. #define MIN_VOLUME        0
  147.  
  148. #define FULL_VOLUME        MAX_VOLUME
  149. #define NO_VOLUME            MIN_VOLUME
  150.  
  151. /* Structure for a list of samples to play asynchronously
  152. */
  153. #if _POWERPC_
  154. #pragma options align=mac68k
  155. #endif
  156. struct SampleList
  157. {
  158.     short int    theSampleID;        /* Sample resource ID or REST_SAMPLE for no sound */
  159.     long        theRate;            /* Sample playback rate */
  160.     short int    theLength;            /* Length of note in 1/60ths of a second */
  161. };
  162. typedef struct SampleList SampleList;
  163. #if _POWERPC_
  164. #pragma options align=reset
  165. #endif
  166.  
  167.  
  168. // SoundQuality
  169. #define jxNoDriver                0                // no driver
  170. #define jxAnalyzeQuality            1                // best driver for speed of mac
  171. #define jxLowQuality            2                // lowest quality (11khz) no intrepolation
  172. #define jxHighQuality            3                // high quality (22khz) no intrepolation
  173. #define jxIntrepLowQuality        4                // lowest quality with 2 pt intrepolation
  174. #define jxIntrepHighQuality        5                // high quality with 2 pt intrepolation
  175. #define jxIntrepBestLowQuality    6                // low quality with 128K memory intrepolation
  176. #define jxIntrepBestHighQuality    7                // high quality with 128K memory intrepolation
  177.  
  178. // Support for hystrical reasons. Bad spellings
  179. #define jxAnalyizeQuality            jxAnalyzeQuality
  180.  
  181. /* NOTE:
  182. **    For future revisions, the numbers will change into bit fields for features as we add
  183. **    support for 16 bit, stereo, etc. Use the defines to pass the values you want. If you 
  184. **    don't now, you may get in trouble in the future.
  185. */
  186. typedef short int SoundQuality;
  187.  
  188. /* FUNCTIONS
  189. */
  190. OSErr    InitSoundMusicSystem(short int maxSongVoices, 
  191.                             short int maxNormalizedVoices, 
  192.                             short int maxEffectVoices,
  193.                             SoundQuality quality);
  194. void        FinisSoundMusicSystem(void);
  195.  
  196. OSErr    ChangeSystemVoices    (short int maxSongVoices, 
  197.                             short int maxNormalizedVoices, 
  198.                             short int maxEffectVoices);
  199.  
  200. OSErr    PauseSoundMusicSystem(void);
  201. OSErr    ResumeSoundMusicSystem(void);
  202.  
  203.  
  204. Handle    DeltaDecompressHandle(Handle theData);
  205.  
  206. OSErr    RegisterSounds(short int *pSoundID, Boolean prePurge);
  207. void        ReleaseRegisteredSounds(void);
  208.  
  209. long        SoundMemorySize(short int *pSoundID);
  210.  
  211. void        ChangeSoundPitch(short int theID, long theRate);
  212. void        BeginSoundList(SampleList * sampleList, short int totalSamples);
  213. Boolean    IsSoundListFinished(void);
  214. void        BeginSound(short int theID, long theRate);
  215. void        LoadSound(short int theID);
  216. void        FreeSound(short int theID);
  217. void        BeginSoundReverse(short int theID, long theRate);
  218. void        BeginSoundSection(short int theID, long theRate, long sectionStart, long sectionEnd);
  219. void        BeginSoundLoop(short int theID, long theRate, long loopStart, long loopEnd);
  220. void        BeginSoundEnvelope(short int theID, long theRate, short int loopTime);
  221. void        BeginSoundEnvelopeProc(short int theID, long theRate, pascal Boolean (*theLoopProc)(short int sampleID));
  222. Boolean    IsSoundFXFinished(void);
  223. Boolean    IsThisSoundFXFinished(short theID);
  224.  
  225. void        PlayTheSample(Ptr pSamp, long sampSize, long sampRate);
  226. void        PlayTheSampleWithID(Ptr pSamp, long sampSize, long sampRate, short int theID);
  227.  
  228. void        SetSoundDoneCallBack(pascal void (*theProcPtr)(short int theID));
  229. void        SetSongDoneCallBack(pascal void (*theProcPtr)(short int theID));
  230.  
  231. void        SetMasterVolume(short int theVolume);
  232. short int    GetMasterVolume(void);
  233.  
  234. void        SetSoundVBCallBack(pascal void (*theProc)(void));
  235.  
  236. Byte *    GetSoundWaveform(short int theID);
  237. long        GetSoundLength(short int theID);
  238. long        GetSoundDefaultRate(short int theID);
  239. long        GetSoundLoopStart(short int theID);
  240. long        GetSoundLoopEnd(short int theID);
  241. short int    GetSoundTime(short int theID, long sampRate);
  242. short int    CalcPlaybackLength(long theRate, long theLength);
  243. void        EndAllSound(void);
  244. void        EndSound(short int theID);
  245. void        EndSoundList(void);
  246. void        PurgeAllSounds(unsigned long minMemory);
  247.  
  248. OSErr    StartFilePlayback(FSSpec *theFile, long theRate, long bufferSize);
  249. Boolean    ServiceFilePlayback(void);
  250. void        ChangeFilePlaybackRate(long theNewRate);
  251. void        EndFilePlayback(void);
  252.  
  253.  
  254. #define kBeginSong                    (short int)0    // kBeginSong, theSongID
  255. #define kBeginSongLooped                (short int)1    // kBeginSongLooped, theSongID
  256. #define kEndSong                    (short int)2    // kEndSong, 0
  257. #define kIsSongDone                    (short int)3    // kIsSongDone, 0
  258. #define kTicksSinceStart                (short int)4    // kTicksSinceStart, 0
  259. #define kPurgeFlag                    (short int)5    // kPurgeFlag, Boolean
  260. #define kLockFlag                    (short int)6    // kLockFlag, Boolean
  261. #define kLoopSongFlag                (short int)7    // kLoopSongFlag, Boolean
  262. #define kFadeOutput                    (short int)8    // kFadeOutput, level (0 to 256)
  263. #define kAutoFadeSoundOut            (short int)10    // kAutoFadeSoundOut, ticks for how fast
  264. #define kAutoFadeSoundIn                (short int)11    // kAutoFadeSoundIn, ticks for how fast
  265. #define kFadeLevel                    (short int)12    // kFadeLevel, short int
  266. #define kSetMasterFade                (short int)13    // kSetMasterFade, short int
  267. #define kChangeOutputQuality            (short int)14    // kChangeOutputQuality, SoundQuality
  268. #define kLoadSong                    (short int)15    // kLoadSong, theSongID
  269. #define kFreeSong                    (short int)16    // kFreeSong
  270. #define kGetErrors                    (short int)17    // kGetErrors, char *
  271. #define kGetMidiClock                (short int)18    // kGetMidiClock
  272. #define kGetMidiBeat                (short int)19    // kGetMidiBeat
  273. #define kGetNextMidiBeat                (short int)20    // kGetNextMidiBeat
  274. #define kSetMidiClock                (short int)21    // kSetMidiClock, pos
  275. #define kGetTempo                    (short int)22    // kGetTempo
  276. #define kGetSongLength                (short int)23    // kGetSongLength
  277.  
  278. #if !THINK_C
  279. #define MUSICDRIVERHANDLER MusicDriverHandler
  280. #endif
  281. pascal unsigned long MusicDriverHandler(short int theMessage, long theData);
  282.  
  283. // Function call interface:
  284.  
  285. #define    BeginSong(theSong)            MusicDriverHandler(kBeginSong, (long)(theSong))
  286. #define    BeginSongLooped(theSong)        MusicDriverHandler(kBeginSongLooped, (long)(theSong))
  287. #define    LoadSong(theSong)            MusicDriverHandler(kLoadSong, (long)(theSong))
  288. #define    FreeSong()                MusicDriverHandler(kFreeSong, 0L)
  289. #define    SetLoopSongFlag(theFlag)        MusicDriverHandler(kLoopSongFlag, (long)(theFlag))
  290. #define    EndSong()                    MusicDriverHandler(kEndSong, 0L)
  291. #define    IsSongDone()                MusicDriverHandler(kIsSongDone, 0L)
  292. #define    SongTicks()                MusicDriverHandler(kTicksSinceStart, 0L)
  293. #define    PurgeSongs(purge)            MusicDriverHandler(kPurgeFlag, (long)(purge))
  294. #define    LockSongs(lock)            MusicDriverHandler(kLockFlag, (long)(lock))
  295. #define    BeginMasterFadeOut(time)        MusicDriverHandler(kAutoFadeSoundOut, (long)(time))
  296. #define    BeginMasterFadeIn(time)        MusicDriverHandler(kAutoFadeSoundIn, (long)(time))
  297. #define    SetMasterFade(level)        MusicDriverHandler(kSetMasterFade, (long)(level))
  298. #define    FadeLevel()                MusicDriverHandler(kFadeLevel, 0L)
  299. #define    ChangeOuputQuality(qual)        MusicDriverHandler(kChangeOutputQuality, (long)(qual))
  300. #define    GetErrors(buffer)            MusicDriverHandler(kGetErrors, (long)(buffer))
  301. #define    GetCurrentMidiClock()        MusicDriverHandler(kGetMidiClock, 0L)
  302. #define    GetCurrentMidiBeat()        MusicDriverHandler(kGetMidiBeat, 0L)
  303. #define    GetNextBeatMidiClock()        MusicDriverHandler(kGetNextMidiBeat, 0L);
  304. #define    SetCurrentMidiClock(clock)    MusicDriverHandler(kSetMidiClock, (long)(clock))
  305. #define    GetCurrentTempo()            MusicDriverHandler(kGetTempo, 0L)
  306. #define    GetSongLength()            MusicDriverHandler(kGetSongLength, 0L)
  307.  
  308. OSErr    BeginSongFromMemory(short int theID, Handle theSongResource, Handle theMidiResource, Boolean loopSong);
  309. long        MaxVoiceLoad(void);
  310.  
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314.  
  315.  
  316. #endif    // HALESTORM_DRIVER
  317.